package com.rcd.viatornisl.android.model.adapters;

import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.rcd.viatornisl.android.R;
import com.rcd.viatornisl.android.model.Interest;

public class InterestAdapter extends ArrayAdapter<Interest> {
	
	public static final String INTERESTS_ID = "interestId";
	    
    public static class InterestHolder {
    	public TextView _InterestTitle;
        public ImageView _InterestLogo;
        public Bundle _InterestBundle;
    }       
    
    public InterestAdapter(Context context, int resource, List<Interest> interests) {
    	// Default operations
    	super(context, resource, interests);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	// Local variables
        InterestHolder interestHolder = null;
        Interest interest = this.getItem(position);
        LayoutInflater inflater = LayoutInflater.from(this.getContext());
        
        // If is a creation
        if (convertView == null) {
        	// Inflate the view
        	convertView = inflater.inflate(R.layout.interest_list_item, parent, false);
        	
        	// Create the holder
        	interestHolder = new InterestHolder();
        	
        	// Setup the holder
        	interestHolder._InterestTitle = ((TextView)convertView.findViewById(R.id.interestName));
        	interestHolder._InterestLogo = ((ImageView)convertView.findViewById(R.id.interestLogo));
        	interestHolder._InterestBundle = new Bundle();
        	
        	// Set the row parameter
        	convertView.setTag(interestHolder);
        }
        
        // Cast the holder
        interestHolder = ((InterestHolder)convertView.getTag());
        
        // Setup the holder
        interestHolder._InterestTitle.setText(interest.getName());
        interestHolder._InterestLogo.setImageResource(R.drawable.ic_default_interest_logo);
        interestHolder._InterestBundle.putInt(INTERESTS_ID, interest.getId());                                         
        
        // Provide the return
        return convertView;                       
    }       

}
